<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>作者信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" >
    <!-- 引入 Element UI 样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

</head>
<body>
<div id="app">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>浏览作者信息</legend>
    </fieldset>

    <div class = "admin-form">
        <el-form :inline="true" :model="author" class="demo-form-inline" style="margin-left: 100px;">
            <el-form-item label="笔名"   >
                <el-input v-model="author.authorName" placeholder="笔名"></el-input>
            </el-form-item>
            <el-form-item label="手机号"   >
                <el-input v-model="author.aphone" placeholder="手机号"></el-input>
            </el-form-item>

            <el-form-item style=" margin-left: 100px;">
                <el-button   type="primary" @click="onSubmit">添加作者</el-button>
            </el-form-item>
        </el-form>
    </div>

    <div class="admin-table">
        <template>
            <el-table
                    :data="tableData"
                    border
                    style="width: 1100px; margin-left: 100px;">
                <el-table-column
                        fixed
                        prop="authorId"
                        label="ID"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="authorName"
                        label="笔名"
                        width="120">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.authorName"  ></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="aphone"
                        label="手机号"
                        width="200">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.aphone"  ></el-input>
                    </template>
                </el-table-column>
                <el-table-column
                        prop=" motto"
                        label="座右铭"
                        width="500">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.motto"  ></el-input>
                    </template>
                </el-table-column>


                <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">修改</el-button>
                        <el-button @click="dlt(scope.row)" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
    </div>

</div>



<!-- 引入 Vue.js 和 Element UI 的脚本 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="http://47.106.66.89:8080/js/axios.min.js"></script>

<script>

    new Vue({
        el: '#app',
        data() {
            return {
                author: {
                    authorName: '',
                    aphone: '',

                },
                tableData: [{
                    authorId: '1',
                    authorName: '王小虎',
                    aphone: '13811111111',
                    motto: '无',



                }],
            }
        },
        mounted() {
             this.select();



        },
        methods: {
            onSubmit() {

                axios.post('author/add', this.author).then(res => {
                    if(res.data == 1){
                        alert("添加成功");
                        this.select();

                    }
                })
            },

            handleClick(row) {
                axios.post('author/update', row).then(res => {
                    if(res.data ==    1){
                        alert("修改成功");
                        this.select();
                    }
                })
            },
            select(){
                axios.get('author/select').then(res => {
                    this.tableData = res.data;

                });
            },
            dlt(row) {
                row.dlt = 0;
                axios.post('author/delete', row).then(res => {

                    if(res.data ==    1){
                        alert("删除成功");
                        this.select();
                    }
                })
            },

        }
    });


</script>
</body>
</html>
